package cn.edu.imnu.Controller;

import cn.edu.imnu.Service.SaleService;
import cn.edu.imnu.entity.Result;
import cn.edu.imnu.entity.dto.SaleListdto;
import cn.edu.imnu.entity.dto.Saleadddto;
import cn.edu.imnu.entity.dto.Saleupdatedto;
import cn.edu.imnu.entity.vo.SaleListvo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;
import java.util.Objects;

@RestController
@ResponseBody
@RequestMapping("/sale")
public class SaleController {
    @Autowired
    private SaleService saleService;
    @PostMapping("/salesLocations")
    public Result getSalesLocations(@RequestBody SaleListdto saleListdto) {

        SaleListvo saleListvo = saleService.selectByCondition(saleListdto);
        if (Objects.isNull(saleListvo) || saleListvo.getList().isEmpty()) {
            return Result.error("未查询到相关数据");
        }
        System.out.println("接收到的参数：" + saleListdto);
        return Result.success(saleListvo);
    }
    @PostMapping("/delete")
    public Result deleteSale(@RequestBody Map<String, Long> requestBody) {
        Long saleId = requestBody.get("saleId");
        System.out.println("接收到的参数：" + saleId);
        return saleService.deleteSale(saleId);
    }
    @PostMapping("/update")
    public Result updateSale(@RequestBody Saleupdatedto dto) {
        return saleService.updateSale(dto);
    }
    @PostMapping("/add")
    public Result addSale(@RequestBody Saleadddto dto) {
        return saleService.addSale(dto);
    }
}
 /*@PostMapping("/salesLocations")
    public Result getSalesLocations(@RequestBody SaleListdto saleListdto) {
        SaleListvo saleListvo = saleService.getSaleList(saleListdto); // 直接获取 SaleListvo
        Map<String , Object> claims = new HashMap<>();
        claims.put("saleid",saleListvo.getSaleId());
        claims.put("salename",saleListvo.getSaleName());
        claims.put("salephone",saleListvo.getSalePhone());
        claims.put("createtime",saleListvo.getCreatetime());
        claims.put("updatetime",saleListvo.getUpdatetime());
        String token  = JwtUtil.genToken(claims);
        Map<String, Object> result = new HashMap<>();
        result.put("token", token);
        result.put("userInfo", saleListvo);
        return Result.success(result);
    }*/